#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>

/*
usage:
./a.out &
1234
kill -USR1 1234
kill -USR2 1234
kill 1234

*/
// handler
static void sig_usr(int);

int main(void){
	// 注册signal handler ， see man signal
	if(signal(SIGUSR1,sig_usr) == SIG_ERR){
		printf("error signal, arg=SIGUSR1\n");
		return 1;
	}
	if(signal(SIGUSR2,sig_usr) == SIG_ERR){
		printf("error signal, arg=SIGUSR2\n");
		return 1;
	}

	for(;;)
		pause();
}


static void sig_usr(int singo){
	if(singo == SIGUSR1)
		printf("received SIGUSR1\n");
	else if(singo == SIGUSR2)
		printf("received SIGUSR2\n");
	else
		printf("received signal %d\n",singo);
}
